{
 "metadata": {
  "name": ""
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import cPickle as pickle\n",
      "import numpy as np"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 29
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "inFile = 'models/test.bin'\n",
      "phoneFile = 'data/timit_sets.txt'"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 38
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# read model training history\n",
      "with open(inFile,'r') as f:\n",
      "    nn_opts = pickle.load(f)\n",
      "    costt = pickle.load(f)\n",
      "    nn_hist = pickle.load(f) "
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 31
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# read phone strings\n",
      "phone_list = []\n",
      "with open(phoneFile,'r') as f:\n",
      "    phone_list = map(lambda x: x.rstrip(), f.readlines())\n",
      "# prepend symbol for blank\n",
      "phone_list.insert(0,'')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 47
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "pyplot.plot(costt,'kx')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 32,
       "text": [
        "[<matplotlib.lines.Line2D at 0xd660950>]"
       ]
      }
     ],
     "prompt_number": 32
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "k =nn_hist.keys()[0]"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 33
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# analyze probs after first iteration\n",
      "cur_prob, cur_delta = nn_hist[k][0]"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 34
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "cur_prob.shape"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 35,
       "text": [
        "(40, 259)"
       ]
      }
     ],
     "prompt_number": 35
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "key_list = nn_hist.keys()[:3]"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 36
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# plot a bunch of the training set \n",
      "for k in key_list:\n",
      "    cur_prob, cur_delta = nn_hist[k][0]\n",
      "    plt.figure()\n",
      "    # Have a look at the colormaps here and decide which one you'd like:\n",
      "    # http://matplotlib.org/1.2.1/examples/pylab_examples/show_colormaps.html\n",
      "    colormap = plt.cm.gist_ncar\n",
      "    plt.gca().set_color_cycle([colormap(i) for i in np.linspace(0, 0.9, 40)])\n",
      "    for p in range(cur_prob.shape[0]):\n",
      "        plt.subplot(2,1,1)\n",
      "        plt.plot(cur_prob[p,:], )\n",
      "        plt.subplot(2,1,2)\n",
      "        plt.plot(cur_delta[p,:], )\n",
      "    # put text for each new argmax phone\n",
      "    plt.subplot(2,1,1)\n",
      "    pmInd = -1\n",
      "    hyp = []\n",
      "    maxInd = np.argmax(cur_prob, axis=0)\n",
      "    for t in range(cur_prob.shape[1]):\n",
      "            if maxInd[t] != pmInd:\n",
      "                pmInd = maxInd[t]\n",
      "                plt.text(t,0.5,phone_list[pmInd])\n",
      "                hyp.append(phone_list[pmInd])\n",
      "    plt.title('-'.join(hyp))\n",
      "    plt.show()\n",
      "    #input('press to continue')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 54
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "plt.close('all')"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 55
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}